package com.demo.Mapper;

import com.demo.DemoApplicationTests;
import com.demo.mapper.nengyuanshujicaiji.nengyuanshujicaijiMapper;
import com.demo.model.nengyuanshujicaiji.nengyuanshujicaiji;
import com.demo.model.nengyuanshujicaiji.nengyuanshujicaijiQ.nengyuanshujicaijiQ;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

public class nysjcjMapper extends DemoApplicationTests {

    @Autowired
    private nengyuanshujicaijiMapper mapper;


    @Test
    public void findAll(){
        nengyuanshujicaijiQ nengyuanshujicaijiQ=new nengyuanshujicaijiQ();
        SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Calendar calendar=Calendar.getInstance();
        calendar.setTime(new Date());
        calendar.set(2023,5,23);
        System.out.println("格式开始时间"+simpleDateFormat.format(calendar.getTime()));
        nengyuanshujicaijiQ.setStartTime(calendar.getTime());
        calendar.set(2023,5,28,10,26,56);
        System.out.println("格式时间"+simpleDateFormat.format(calendar.getTime()));
        nengyuanshujicaijiQ.setEndTime(calendar.getTime());
        List<nengyuanshujicaiji> list=mapper.findAll(nengyuanshujicaijiQ);
        list.forEach(System.out::println);
    }

    @Test
    public void findAllpaging(){
        List<nengyuanshujicaiji> list=mapper.findAllpaging(0,2,null);
        list.forEach(System.out::println);
    }

    @Test
    public void countNum(){
        nengyuanshujicaijiQ nengyuanshujicaijiQ=new nengyuanshujicaijiQ();
        nengyuanshujicaijiQ.setDeviceName("仪");
        int i=mapper.countNumber(nengyuanshujicaijiQ);
        System.out.println(i);
    }


    @Test
    public void save() throws ParseException {
        nengyuanshujicaiji nengyuanshujicaiji=new nengyuanshujicaiji();
        nengyuanshujicaiji.setId(null);
        nengyuanshujicaiji.setDeviceName("标牌打刻机3");
        nengyuanshujicaiji.setQuantityProduced(112);
        nengyuanshujicaiji.setUnitPowerConsumption(665523);
        nengyuanshujicaiji.setTotalPowerConsumption(BigInteger.valueOf(88985562));
        nengyuanshujicaiji.setUnitCarbonEmission(new BigDecimal(66223351));
        nengyuanshujicaiji.setTotalCarbonEmissions(new BigDecimal(77885566));
        Calendar calendar=Calendar.getInstance();
        Date date=new Date();
        calendar.setTime(date);
        calendar.set(2023,5,26,17,26,02);
        SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        simpleDateFormat.format(calendar.getTime());
        String starttime= simpleDateFormat.format(calendar.getTime());
        System.out.println("格式后的开始时间"+simpleDateFormat.parse(starttime));
        nengyuanshujicaiji.setStartTime(simpleDateFormat.parse(starttime));

        calendar.set(2023,5,30,20,30,30);
       String endtime= simpleDateFormat.format(calendar.getTime());
        System.out.println("格式后的结束时间"+simpleDateFormat.parse(endtime));
        nengyuanshujicaiji.setEndTime(simpleDateFormat.parse(endtime));

       int i= mapper.save(nengyuanshujicaiji);
        System.out.println(i+"结果");
    }

    @Test
    public void updata() throws ParseException {
        nengyuanshujicaiji nengyuanshujicaiji=new nengyuanshujicaiji();
        nengyuanshujicaiji.setId(125);
        nengyuanshujicaiji.setDeviceName("标牌打刻机修改");
        nengyuanshujicaiji.setQuantityProduced(666);
        nengyuanshujicaiji.setUnitPowerConsumption(666666);
        nengyuanshujicaiji.setTotalPowerConsumption(BigInteger.valueOf(66666666));
        nengyuanshujicaiji.setUnitCarbonEmission(new BigDecimal(66666666));
        nengyuanshujicaiji.setTotalCarbonEmissions(new BigDecimal(66666666));
        Calendar calendar=Calendar.getInstance();
        Date date=new Date();
        calendar.setTime(date);
        calendar.set(2023,5,16,16,16,16);
        SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        simpleDateFormat.format(calendar.getTime());
        String starttime= simpleDateFormat.format(calendar.getTime());
        System.out.println("格式后的开始时间"+simpleDateFormat.parse(starttime));
        nengyuanshujicaiji.setStartTime(simpleDateFormat.parse(starttime));

        calendar.set(2023,6,16,16,16,16);
        String endtime= simpleDateFormat.format(calendar.getTime());
        System.out.println("格式后的结束时间"+simpleDateFormat.parse(endtime));
        nengyuanshujicaiji.setEndTime(simpleDateFormat.parse(endtime));

        int i= mapper.update(nengyuanshujicaiji);
        System.out.println(i+"结果");
    }

    @Test
    public void del(){
        int i=mapper.delById(125);
        System.out.println(i);
    }

    @Test
    public void delall(){
        Integer ids[]=new Integer[]{123,124};
       int i= mapper.delByIdIn(ids);
        System.out.println(i);
    }
}
